#!/usr/bin/perl
my $boundary = 'LXL.CN.';
my @boundary = ( 0 .. 9, 'A' .. 'F' );
srand( time ^ $$ );
for ( my $i = 0 ; $i++ < 6 ; ) {
    $boundary .= $boundary[ rand(@boundary) ];
}
print "Content-type: text/html\n\n";
print q{<script>
function $(e){
    return top.document.getElementById(e);
}
function s(e,h,s){
    if(s == 1){
        s = 'up.gif';
    }
    else{
        s = 'down.gif';
    }
    return top.setInnerHTML(e,h + '<img src="'+s+'">');
}
var d = 'demo';
</script>};
my $netstat  = '/usr/bin/netstat';
my $grep     = '/usr/bin/grep';
my $wc       = '/usr/bin/wc';
my $i = 0;
my $old = 0;
for ( ; ; ) {
    $i++;
    my $msg;
    $msg = `$netstat -an | $grep ESTABLISHED | $wc -l`;
    $msg =~ s/^\s+|\s+$//g;
    if($old != $msg){
        printf(
            "<script>s(\$(d),'%s | %d | %s',%s);</script>\n",
            $msg, $i, my $time = localtime, $old < $msg ? 1 : 0
        );
        $old = $msg;
    }
    sleep(1)
    #else{
    #    sleep(2);
    #}
}
exit 0;